import * as types from "../types/orderInfoTypes";

const initialState = {
  initing: true,
  loading: false,
  error: undefined,
  orderInfo: {},
  storeInfo: {},
};

export default function orderInfoReducer(state = initialState, action) {
  switch (action.type) {
    case types.ORDERINFO_LOADING:
      return {
        ...state,
        loading: true,
      };
    case types.ORDERINFO_INIT:
      return {
        ...state,
        initing: true,
      };
    case types.ORDERINFO_DOWN:
      return {
        ...state,
        loading: false,
        initing: false,
        orderInfo: action.orderInfo,
      };
    case types.ORDERINFO_ERROR:
      return {
        ...state,
        loading: false,
        initing: false,
        error: action.error,
      };
    case types.STOREINFO_DOWN:
      return {
        ...state,
        storeInfo: action.storeInfo,
      };
    case types.STOREINFO_ERROR:
      return {
        ...state,
        error: action.error,
      };
    case types.ORDERINFO_UNMOUNT:
      return {
        ...initialState,
      };
    default:
      return state;
  }
}
